package com.jbinfo.mongoot.controller;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.jbinfo.mongoot.operation.order.Order;
import com.jbinfo.mongoot.util.XiMethodUtil;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/order")
@Api("fuzhou-order类API")
public class OrderController {
	@Autowired
	private MongoTemplate mongoTemplate;
	
	@ApiOperation("新增或更新order")
	@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
	public Map<String, Object> updateStatus(@ModelAttribute  Order order) throws ParseException {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", 1);
		map.put("description", "");
		map.put("code", "");
		DBCollection collection = mongoTemplate.getCollection(mongoTemplate.getCollectionName(order.getClass()));
		DBObject query =new BasicDBObject();
		query.put("order_id", order.getOrder_id());
//		query.put("servant_id", order.getServant_id());
		DBObject findOne = collection.findOne(query);
		DBObject update=XiMethodUtil.method(order,findOne);
		collection.update(query, update, true, true);
		return map;
	}
}
